var  mongoose = require("mongoose"),
	db = mongoose.connection;
//banner数据模型
var bannerSchema = new mongoose.Schema({
		title : {type : String , required : true},
		url : {type : String},
		imgUrl : {type : String , required : true},
		releaseTime : {type : String , required : true , default : new Date()},
	}),
	bannerS = db.model("banner" , bannerSchema);
function Banner(){};
//获取
Banner.prototype.getBanner = function(data , callback){
	bannerS.find(data , function(error , data){
		if(error){
			return callback(error);
		};
		callback(null , data);
	});
};
//添加
Banner.prototype.addBanner = function(data , callback){
	data = {
		title : data.title,
		url : data.url,
		imgUrl : data.imgUrl
	};
	//保存
	bannerS.create(data , function(error , data){
		if(error){
			return callback(error);
		};
		return callback(null , data);
	});
};
//删除
Banner.prototype.remove = function(data , callbck){
	bannerS.remove(data , function(error , data){
		if(error){
			return callbck(error);
		};
		return callbck(null , data);
	});
};
//接口
module.exports = new Banner();
